package com.ellricky.baselib.ui.student

import android.os.Bundle
import android.view.View
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.student.StudentClassRecordAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.ClassStuRecord
import com.ellricky.baselib.entity.new.CourseType
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback
import kotlinx.android.synthetic.main.base_layout_rv.*

class StudentClassRecordFragment :
    BaseRefreshFragment<Void, BasePresenter<Void>, ClassStuRecord>() {

    private var typeId: Int = 0
    private var studentId: String = ""
    private val courseType: String by lazy {
        arguments?.getString(BaseConstant.KEY_NAME) ?: ""
    }

    override fun initUIView(view: View?) {
        super.initUIView(view)
        typeId = arguments?.getInt("type_id") ?: 0
        studentId = arguments?.getString(BaseConstant.KEY_ID) ?: ""
        hideToolBar()
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap["action"] = "courseJobList"
        paramMap["course_type_id"] = typeId.toString()
        paramMap["member_id"] = studentId
        paramMap["eid"] = LocalCacheUtil.getUid()
    }

    companion object {
        fun newInstance(
            typeId: String,
            studentId: String,
            courseType: String
        ): StudentClassRecordFragment {
            val fragment = StudentClassRecordFragment()
            val bundle = Bundle()
            bundle.putInt("type_id", typeId.toInt())
            bundle.putString(BaseConstant.KEY_ID, studentId)
            bundle.putString(BaseConstant.KEY_NAME, courseType)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<ClassStuRecord>(requireActivity(), false) {
            override fun onSuccess(data: MutableList<ClassStuRecord>, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onLoadFinish(ArrayList<ClassStuRecord>(), refresh)
            }
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<ClassStuRecord> {
        return StudentClassRecordAdapter(courseType)
    }

    override fun getUrlPath(): String {
        return ""
    }
}